package com.example.musicplayer

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

class RecommendedSongAdapter(val recList:List<rec>):RecyclerView.Adapter<RecommendedSongAdapter.ViewHolder>() {

    inner class ViewHolder(view:View):RecyclerView.ViewHolder(view) {
        val recImage:ImageView=view.findViewById(R.id.recImage)
        val recName:TextView=view.findViewById(R.id.recName)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view=LayoutInflater.from(parent.context).inflate(R.layout.recommended_song_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val recData=recList[position]
        holder.recName.text=recData.name
        Glide.with(holder.itemView.context)
            .load(recData.recImgUrl)
            .into(holder.recImage)
    }

    override fun getItemCount(): Int {
        return recList.size
    }
}